<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>正则表达式演示实例</title>

</head>
<body>
	<form action="" method="post" OnSubmit="return checkData();">
		<br>输入一个数字：<input type="text" name="num"> <br>输入一个整数：<input
			type="text" name="intnum"> <br>输入电子邮件：<input type="text"
			name="email">
		<p>
			<input type="submit" value="提交">
		</p>
	</form>
</body>
</html>

<script type="text/javascript">
	function checkData() {
		var txt = document.forms[0].num.value;
		if (txt.search("^\\d+(\\.\\d+)*$") != 0) {
			alert("请输入一个数字");
			document.forms[0].num.select();
			return false;
		}
		var txt2 = document.forms[1].intnum.value;
		if (txt2.search("^?\\d+$") != 0) {
			alert("请输入一个整数");
			document.forms[1].intnum.select();
			return false;
		}
		var txt3 = document.forms[2].email.value;
		if (txt3.search("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$") != 0) {
			alert("请输入合法的电子邮件地址");
			document.forms[2].email.select();
			return false;
		}
		alert("检验通过！");
		return true;
	}
</script>